package com.fjb.service.banner.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fjb.common.entity.HttpCode;
import com.fjb.common.entity.JsonTotalResult;
import com.fjb.common.entity.PageQuery;
import com.fjb.mapper.banner.BannerInfoMapper;
import com.fjb.pojo.banner.BannerInfo;
import com.fjb.pojo.banner.query.BannerInfoQuery;
import com.fjb.service.banner.BannerInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

/**
 * <p>
 * 广告信息 服务实现类
 * </p>
 *
 * @author hemiao
 * @since 2020-01-31
 */
@Service
public class BannerInfoServiceImpl extends ServiceImpl<BannerInfoMapper, BannerInfo> implements BannerInfoService {
	
	@Autowired
	private BannerInfoMapper bannerInfoMapper;
	
	@Override
	public JsonTotalResult<List<BannerInfo>> selectPageList(BannerInfoQuery bannerInfoQuery, PageQuery pageQuery) {
		PageHelper.startPage(pageQuery.getCurrentPage(), pageQuery.getPageSize());
		QueryWrapper<BannerInfo> queryWrapper = new QueryWrapper<BannerInfo>();
		Integer id = bannerInfoQuery.getId();
		if(id!=null) {	
			queryWrapper.eq("id", id);
		}
		List<BannerInfo> infoList = bannerInfoMapper.selectList(queryWrapper);
		PageInfo<BannerInfo> pageInfo = new PageInfo<BannerInfo>(infoList);
		return new JsonTotalResult<List<BannerInfo>>(infoList, HttpCode.SUCCESS, pageInfo.getTotal());
	}

}
